<template>
	<div>
		<div class="container">
			<div class="search-box">
				<el-input v-model="query.name" placeholder="项目编号" class="search-input mr10" clearable></el-input>
				<el-button type="primary" :icon="Search">搜索</el-button>
			</div>
			<slot name="button"></slot>
			<el-table ref="multipleTable" :data="tableData" border class="table" header-cell-class-name="table-header">
				<el-table-column prop="id" label="ID" width="55" align="center"></el-table-column>
				<el-table-column prop="proj_id" label="项目编号" align="center"></el-table-column>
				<el-table-column prop="proj_name" label="项目名称" align="center"></el-table-column>
				<el-table-column prop="cli_name" label="客户名称" align="center"></el-table-column>
				<el-table-column prop="cli_address" label="客户地址" align="center"></el-table-column>
				<el-table-column prop="contactor" label="联系人" align="center"></el-table-column>
				<el-table-column prop="email" label="邮箱" align="center"></el-table-column>
				<el-table-column prop="cli_phone" label="电话号码" align="center"></el-table-column>
				<el-table-column prop="cre_time" label="有效日期" align="center"></el-table-column>
				<el-table-column label="操作" width="280" align="center">
					<template #default="scope">
						<el-button
							type="primary"
							size="small"
							:icon="Edit"
							v-permiss="15"
							@click="handleEdit(scope.$index, scope.row)"
						>
							编辑 
						</el-button>
						<el-button
							type="danger"
							size="small"
							:icon="Delete"
							v-permiss="15"
							@click="handleDelete(scope)"
						>
							删除
						</el-button>
					</template>
				</el-table-column>
			</el-table>
			<div class="pagination">
				<el-pagination
					background
					layout="total, prev, pager, next"
					:current-page="query.pageIndex"
					:page-size="query.pageSize"
					total="100"
				></el-pagination>
			</div>
		</div>
		<el-dialog
			title="样品领用单"
			width="1450px" 
			destroy-on-close
			:close-on-click-modal="false"
		>
		</el-dialog>
		<el-dialog
			:title="idEdit ? '编辑用户' : '新增用户'"
			v-model="visible"
			width="500px"
			destroy-on-close
			:close-on-click-modal="false"
		>
			<TableEdit :data="rowData" :edit="idEdit"  />
		</el-dialog>
	</div>
</template>

<script setup lang="ts" name="basetable">
import { pa } from 'element-plus/es/locale';
import { ref,reactive } from 'vue';
import { ElMessage, ElMessageBox } from 'element-plus';
import { Delete, Search,Edit, Sort, CirclePlusFilled, View } from '@element-plus/icons-vue';
import TableEdit from '../../../components/tables/project_edit.vue';
import useProject from '../../hooks/Project/useProject'

// 获取表格数据                                                                                                                                                                           
interface TableItem { 
	id: number;
	proj_id: string;
	proj_name: string;
	cli_id: string;
	cli_address: string;
	cli_phone: string;
	cli_name: string;
	contactor: string;
	cre_user: string;
	cre_time: string;
	flag: boolean;
}

const tableData = ref<TableItem[]>([]);
const pageTotal = ref(0);

const query = reactive({
	address: '',
	name: '',
	pageIndex: 1,
	pageSize: 10
});

// 查询操作
// const handleSearch = () => {
// 	query.pageIndex = 1;
// 	getData();
// };
// 分页导航
// const handlePageChange = (val: number) => {
// 	query.pageIndex = val;
// 	getData();
// };

// 删除操作
const handleDelete = (scope:any) => {
	// 二次确认删除
	ElMessageBox.confirm('确定要删除吗？', '提示', {
		type: 'warning'
	})
		.then(() => {
			// delProject(scope.row.id);
			ElMessage.success('删除成功');
			tableData.value.splice(scope.$index, 1);
	})
		.catch(() => {});
};

const visible = ref(false);
let idx: number = -1;
const idEdit = ref(false);
const rowData = ref({});
const handleEdit = (index: number, row: TableItem) => {
	idx = index;
	rowData.value = row;
	idEdit.value = true;
	visible.value = true;
};

</script>

<style scoped>
.search-box {
	margin-bottom: 20px;
}

.search-input {
	width: 200px;
}

.mr10 {
	margin-right: 10px;
}
.table-td-thumb {
	display: block;
	margin: auto;
	width: 40px;
	height: 40px;
}
</style>